package code.cando;

import java.util.Arrays;
import java.util.HashMap;

/**
 * author : yeswater
 * date : 2023/12/4
 */

public class T001 {
    public static void main(String[] args) {
        // int[] nums = {2,7,11,15};
        int[] nums = {3,3};
        // int target = 9;
        int target = 6;
        System.out.println(Arrays.toString(twoSum(nums, target)));

    }
    
    public static int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i]) && i != map.get(target - nums[i]) ) {
                return new int[] {i, map.get(target - nums[i])};
            }
            map.put(nums[i], i);
        }
        return null;
    }
}
